package router

import (
	"admin-nexus-backend/internal/handler"
	"admin-nexus-backend/internal/middleware"
	"admin-nexus-backend/internal/service"

	"github.com/gin-gonic/gin"
)

// SetupPermissionRoutes 设置权限管理路由
func SetupPermissionRoutes(
	router *gin.RouterGroup,
	permissionMiddleware *middleware.PermissionMiddleware,
	permissionCacheService *service.PermissionCacheService,
	permissionLogService *service.PermissionLogService,
	userService *service.UserService,
) {
	permissionHandler := handler.NewPermissionHandler(
		permissionCacheService,
		permissionLogService,
		userService,
	)

	permissions := router.Group("/permissions")
	permissions.Use(permissionMiddleware.AdminOnly()) // 仅管理员访问
	{
		// 权限缓存管理
		permissions.POST("/cache/clear", permissionHandler.ClearPermissionCache) // 清除权限缓存
		permissions.GET("/cache/stats", permissionHandler.GetCacheStats)         // 缓存统计

		// 权限日志管理
		permissions.GET("/logs", permissionHandler.GetPermissionLogs)                         // 权限日志列表
		permissions.GET("/logs/stats", permissionHandler.GetPermissionLogStats)               // 权限日志统计
		permissions.POST("/logs/clean", permissionHandler.CleanOldLogs)                       // 清理旧日志
		permissions.GET("/users/:userId/history", permissionHandler.GetUserPermissionHistory) // 用户权限历史

		// 权限检查
		permissions.POST("/check", permissionHandler.CheckPermission) // 权限检查
	}
}
